define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'disassemble/order/index' + location.search,
                    // add_url: 'disassemble/order/add',
                    edit_url: 'disassemble/order/edit',
                    // del_url: 'disassemble/order/del',
                    // multi_url: 'disassemble/order/multi',
                    // import_url: 'disassemble/order/import',
                    table: 'back_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'userid', title: __('Userid')},
                        {field: 'numbers', title: __('Numbers'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        // {field: 'storeids', title: __('Storeids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'store_admins', title: __('Store_admins'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'end_storeid', title: __('End_storeid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'disassemble.tags', title: __('Disassemble.tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        // {field: 'disassemble.name', title: __('Disassemble.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'end_price', title: __('End_price'), operate:'BETWEEN'},
                        {field: 'end_status', title: __('End_status'), searchList: {"0":__('End_status 0'),"1":__('End_status 1'),"2":__('End_status 2')}, formatter: Table.api.formatter.status},

                        {field: 'car_images', title: __('Car_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'car_weight', title: __('Car_weight'), operate:false},

                        {field: 'num_image', title: __('Num_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'vin', title: __('Vin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'num_text', title: __('Num_text'), operate: 'LIKE'},
                        {field: 'is_sanyuan', title: __('Is_sanyuan'), operate: 'LIKE'},
                        // {field: 'car_material', title: __('Car_material'), operate: 'LIKE'},
                        // {field: 'car_nums', title: __('Car_nums')},
                        {field: 'is_diving', title: __('Is_diving'), searchList: {"0":__('Is_diving 0'),"1":__('Is_diving 1'),"2":__('Is_diving 2'),"3":__('Is_diving 3')}, formatter: Table.api.formatter.normal},
                        {field: 'city', title: __('City'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
                        {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
                        {field: 'gettime', title: __('Gettime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'getphone', title: __('Getphone'), operate: 'LIKE'},
                        {field: 'distance', title: __('Distance'), operate:'BETWEEN'},

                        {field: 'enr_image', title: __('Enr_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'vehicle_image', title: __('Vehicle_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'plate_num', title: __('Plate_num'), operate: 'LIKE'},
                        {field: 'vehicle_type', title: __('Vehicle_type'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'car_model', title: __('Car_model'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'engine_num', title: __('Engine_num'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'use_character', title: __('Use_character'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'owner', title: __('Owner'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_company', title: __('Is_company'), searchList: {"0":__('Is_company 0'),"1":__('Is_company 1')}, formatter: Table.api.formatter.normal},

                        {field: 'car_time', title: __('Car_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD"},
                        {field: 'car_status', title: __('Car_status'), searchList: {"0":__('Car_status 0'),"1":__('Car_status 1'),"2":__('Car_status 2'),"3":__('Car_status 3')}, formatter: Table.api.formatter.normal},
                        {field: 'is_give', title: __('Is_give'), searchList: {"0":__('Is_give 0'),"1":__('Is_give 1')}, formatter: Table.api.formatter.normal},
                        {field: 'file_status', title: __('File_status'), searchList: {"0":__('File_status 0'),"1":__('File_status 1')}, formatter: Table.api.formatter.normal},
                        {field: 'file_desc', title: __('File_desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'overtype', title: __('Overtype'), searchList: {"0":__('File_status 0'),"1":__('File_status 1')}, formatter: Table.api.formatter.normal},

                        {field: 'face_image', title: __('Face_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'back_image', title: __('Back_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'username', title: __('Username'), operate: 'LIKE'},
                        // {field: 'genderdata', title: __('Genderdata'), searchList: {"male":__('Genderdata male'),"female":__('Genderdata female')}, formatter: Table.api.formatter.normal},
                        // {field: 'idcard', title: __('Idcard'), operate: 'LIKE'},
                        {field: 'letter_image', title: __('Letter_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'contract_image', title: __('Contract_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'yy_image', title: __('Yy_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},


                        {field: 'tuoche_amount', title: __('拖车报价'), operate:false},
                        {field: 'tuoche_distance', title: __('拖车里程'), operate:false},
                        {field: 'tuoche_image', title: __('路线截图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        // {field: 'vehicle_back', title: __('Vehicle_back'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'check_images', title: __('Check_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'attachfile', title: __('Attachfile'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'confirmtime', title: __('Confirmtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'begintime', title: __('Begintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'overtime', title: __('Overtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons:[
                                {
                                    name: '确认合作',
                                    text: __(''),
                                    title: __('确认合作'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-unlock-alt',
                                    url: 'disassemble/order/do_price',
                                    confirm: '确认合作',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'confirm_fee',
                                    text: __(''),
                                    title: __('确认费用'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: 'fa fa-check-circle',
                                    url: 'disassemble/order/do_carer/type/confirm',
                                    confirm: '确认费用？',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'reject_fee',
                                    text: __(''),
                                    title: __('驳回费用'),
                                    classname: 'btn btn-xs btn-warning btn-ajax',
                                    icon: 'fa fa-times-circle',
                                    url: 'disassemble/order/do_carer/type/reject',
                                    confirm: '驳回费用？',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: '开始检测',
                                    text: __(''),
                                    title: __('开始检测'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-steam',
                                    url: 'disassemble/order/begin',
                                    confirm: '确认开始检测',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: '打款',
                                    text: __(''),
                                    title: __('打款'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-opencart',
                                    url: 'disassemble/order/payment',
                                    confirm: '确认打款',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: '打款确认',
                                    text: __(''),
                                    title: __('打款确认'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-gavel',
                                    url: 'disassemble/order/over',
                                    confirm: '确认已打款',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                            ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
